﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace _2.ID
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string ID = textBox1.Text;
            string _IDRe18 = @"^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$";
            if (Regex.IsMatch(ID, _IDRe18)){
                string[] arrArrifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');
                string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');
                int sum = 0;
                for (int i = 0; i < 17; i++)
                {
                    sum += int.Parse(Wi[i]) * int.Parse(ID[i].ToString());
                }
                if (arrArrifyCode[sum % 11] != ID[17].ToString())
                {
                    DialogResult dr = MessageBox.Show("最后一位校验位错误", "警告", MessageBoxButtons.OK);
                }
                else
                {
                    DialogResult dr = MessageBox.Show("身份证合法", "提示", MessageBoxButtons.OK);
                }
            }
            else 
            {
                DialogResult dr = MessageBox.Show("身份证格式不符合", "警告", MessageBoxButtons.OK);
            }
        }
    }
}
